package internal

import (
	"github.com/name5566/leaf/gate"
	//"github.com/name5566/leaf/log"
	//"github.com/name5566/leaf/timer"
	//"game-server/msg"
	"github.com/name5566/leaf/log"
	"game-server/db"
	"game-server/base"
)

func init() {
	skeleton.RegisterChanRPC("NewAgent", rpcNewAgent)
	skeleton.RegisterChanRPC("CloseAgent", rpcCloseAgent)
}

func rpcNewAgent(args []interface{}) {
	a := args[0].(gate.Agent)
	_ = a
}

func rpcCloseAgent(args []interface{}) {
	a := args[0].(gate.Agent)
	log.Debug("在这断开链接",a.UserData())

	if a.UserData() != nil{
		log.Debug("aaaaaaaa %v", a.UserData())
		userId := a.UserData().(int32)
		// 离开房间存一次数据库
		var msgsInfo []int32
		msgsInfo = append(msgsInfo, userId)
		playerInfo := base.Get("user",userId).(base.PlayerInfo)
		playerInfo.NameNum = 0
		base.Put("user",userId,playerInfo)
		skeleton.AsynCall(db.ChanRPC, "UpdateUser", msgsInfo, func(ret interface{}, err error) {

		})
	}
	// todo 在这里存库
	_ = a
}
